home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ShareWare OnLine 2
/
ShareWare OnLine Volume 2 (CMS Software)(1993).iso
/
games2
/
rotise12.zip
/
ROTISE.C
< prev
next >
Wrap
Text File
|
1993-03-28
|
6KB
|
228 lines
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define R_VERSION "1.2" /* Version string */
#ifdef __ANSI__
#include <stdlib.h>
#endif
#ifdef __TURBOC__
#include <io.h>
#undef R_VERSION
#define R_VERSION "1.2 .. " __DATE__
#endif
#ifdef __MSDOS__
#include <conio.h>
#include <stdlib.h>
#endif
#define GLOBALS
#include "rotise.h"
/* External data referenced */
extern CMDLIST CmdTable[]; /* commands.c - list of commands */
extern BOOL Use_IBM_Chars; /* report.c - use funky ascii in report? */
/* getopt() stuff */
extern char *optarg;
extern int opterr;
extern int optind;
/* External routines used */
int gettkline PROTO( ( FILE *, char *, int, int *, char **, int) );
/* Local data publicly available */
char *TokenV[MAX_TOKENS]; /* command line tokens */
int TokenC; /* How many tokens */
int Cmd; /* Command # being executed */
int InputLine; /* Line # of current file */
BOOL Verbose = FALSE; /* How talkative to be */
char *InputFilename; /* Filename being read */
/* Private data */
char *Freelistfile; /* Filename for freelist */
char *Worksheetfile; /* Filename for worksheet */
/* NONE */
int main ARGLIST( ( argc, argv ) )
NFARG( int argc )
FARG( char *argv[] )
{
int ch;
int weeks;
weeks = -1; /* Haven't got # of weeks yet */
while ( ( ch = getopt( argc, argv, "iVf:v:s:w:" ) ) != EOF )
{ /* Parse command line arguments */
switch ( ch )
{
case 'i': /* Use IBM chars in report */
Use_IBM_Chars = TRUE;
break;
case 'f': /* Freelist */
Freelistfile = optarg;
break;
case 's': /* Worksheet */
Worksheetfile = optarg;
break;
case 'v': /* Verbosity */
if ( optarg == NULL )
Verbose = 1;
else
Verbose = atoi( optarg );
break;
case 'w': /* Weeks to init database to */
weeks = atoi( optarg );
break;
case 'V':
printf("Version: %s.\n", R_VERSION );
break;
default:
fprintf( stderr, "Unknown switch: %c.\n", ch );
case '?':
usage();
exit( 1 );
break;
}
}
/* Do datafiles */
if ( optind >= argc )
{ /* No datafiles specified? */
usage();
exit( 1 );
}
if ( weeks <= 0 )
weeks = MAX_WEEKS;
pdb_init( 1, weeks );
for ( ; optind < argc; ++optind )
{
VERBOSE( 1, "Parse file: %s.\n", argv[ optind ] );
if ( !parse_file( argv[ optind ] ) )
{ /* if we have problems with a file, just quit */
return 1;
}
}
report();
if ( Freelistfile != NULL )
freelist( Freelistfile );
if ( Worksheetfile )
worksheet( Worksheetfile );
return 0;
}
void usage NOARGLIST
{
fprintf( stderr, "Usage: rotise [-v[n] -V -i -wn -sfilename -ffilename] datafile\n" );
fprintf( stderr, " Where:\n\tdatafile : data file to be parsed.\n");
fprintf( stderr, "\t-v : Verbose mode.\n");
fprintf( stderr, "\t-i : Use IBM chars in report.\n");
fprintf( stderr, "\t-sfilename : Generate worksheet.\n");
fprintf( stderr, "\t-wN : Init database to N weeks.\n");
fprintf( stderr, "\t-ffilename : Generate free agent list.\n");
fprintf( stderr, "\t-V : Print version.\n");
}
/*
BOOL parse_file( char *fname )
Parse a rotisserie data file.
ACCEPTS:
char *fname - name of file to be parsed
RETURNS:
BOOL <value> - TRUE if okay, FALSE if couldn't open the file
*/
BOOL parse_file ARGLIST( (fname) )
FARG( char *fname )
{
char cmdline[100], *cmdstr;
int cmdX, tlen, cmdcnt;
FILE *fp;
if ( (fp = fopen( fname, "r" )) == NULL )
{ /* couldn't open command file, complain and return */
fprintf( stderr, "\n!ERROR! Unable to open file %s because\n", fname );
perror( "!ERROR! parse_data" );
return FALSE;
}
InputLine = 0;
InputFilename = fname;
while ( gettkline( fp, &cmdline[0], 100, &TokenC, &TokenV[0], MAX_TOKENS ) >= 0 )
{ /* read in and parse each line */
InputLine++;
if ( TokenC == 0 )
{ /* we didn't get any arguments, try next line */
continue;
}
VERBOSE( 6, "\tCommand: %s.\n", TokenV[0] );
tlen = strlen( TokenV[0] );
cmdcnt = 0;
Cmd = -1;
for ( cmdX = 0; ( cmdstr = CmdTable[cmdX].cmd ) != NULL;
++cmdX )
{ /* search thru table looking for command that matches */
if ( strnicmp( TokenV[0], cmdstr, tlen ) == 0 )
{ /* matched for what was passed */
Cmd = cmdX;
cmdcnt++;
}
else if ( strnicmp( cmdstr, TokenV[0], strlen(cmdstr) ) == 0 )
{ /* matches the other way */
Cmd = cmdX;
cmdcnt++;
}
}
if ( cmdcnt == 1 )
{ /* okay, found the command, so call routine */
if ( (*CmdTable[Cmd].cmd_func)( TokenC, &TokenV[0] ) == FALSE )
{ /* Fatal error */
return FALSE;
}
}
else if ( cmdcnt > 1 )
{ /* ambiguous command */
fprintf( stderr, "File %s, Line %d: Ambiguous command - %s.\n", fname,
InputLine, TokenV[0] );
}
else
{ /* no command by that name */
fprintf( stderr, "File %s, Line %d: Unknown command - %s.\n", fname,
InputLine, TokenV[0] );
}
}
return TRUE;
}
/**********************/
/* rdb_error - print out an error message for the interpreter
/*********************/
void rdb_error ARGLIST( (s1, s2) )
NFARG( char *s1 )
FARG( char *s2 )
{
fprintf( stderr, "!ERROR!File %s, Line %d: ", InputFilename, InputLine );
fprintf( stderr, "%s %s\n", s1, s2 );
}